package com.ice.body.business.controller;
import com.ice.body.business.model.ReagentOutDetailModel;
import com.ice.body.business.service.ReagentOutDetailService;
import io.swagger.annotations.ApiOperation;
import com.ice.base.controller.BaseController;
import com.github.pagehelper.PageHelper;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.ice.base.result.ResponseResult;
import com.ice.base.result.AjaxResult;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2021-06-22
 * Time: 04:24
 */
@RestController
@ApiIgnore(value = "业务接口-借出明细表")
public class ReagentOutDetailController extends BaseController{
    //---------------------------业务接口-借出明细表-----------------------start
    @Resource
    private ReagentOutDetailService reagentOutDetailService;
    
    @ApiOperation(value = "业务接口-借出明细表-新增")
    @PostMapping("/api/ReagentOutDetail/insert")
    public AjaxResult<ReagentOutDetailModel> insert_ReagentOutDetail(ReagentOutDetailModel model) {
        AjaxResult r = ResponseResult.success();
        try{
            reagentOutDetailService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "业务接口-借出明细表-删除")
    @PostMapping("/api/ReagentOutDetail/deleteById")
    public AjaxResult<ReagentOutDetailModel> deleteById_ReagentOutDetail(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
            Integer count = reagentOutDetailService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "业务接口-借出明细表-更新")
    @PostMapping("/api/ReagentOutDetail/updateById")
    public AjaxResult<ReagentOutDetailModel> update_ReagentOutDetail(ReagentOutDetailModel model) {
        AjaxResult r = ResponseResult.success();
        try{
            Integer count = reagentOutDetailService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "业务接口-借出明细表-查询一个")
    @PostMapping("/api/ReagentOutDetail/selectById")
    public AjaxResult<ReagentOutDetailModel> selectById_ReagentOutDetail(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
           ReagentOutDetailModel model = reagentOutDetailService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "业务接口-借出明细表-查询多个")
    @PostMapping("/api/ReagentOutDetail/selectAll")
    public AjaxResult<ReagentOutDetailModel> selectList_ReagentOutDetail(ReagentOutDetailModel model) {
        AjaxResult r = ResponseResult.success();
        try{
           List<ReagentOutDetailModel> list = reagentOutDetailService.selectListByModel(model);
           r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "业务接口-借出明细表-查询分页")
    @PostMapping("/api/ReagentOutDetail/selectListByPageHelper")
    public AjaxResult<ReagentOutDetailModel> selectListByPageHelper_ReagentOutDetail(@RequestParam(name = "pageSize") Integer pageSize,
                                                                                     @RequestParam(name = "pageNum") Integer pageNum,
                                                                                     ReagentOutDetailModel model,
                                                                                     String keyWord){
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
           if(StringUtils.isEmpty(keyWord)) {
               list = reagentOutDetailService.selectListByModel(model);
           } else {
               list = reagentOutDetailService.selectListByKeyWord(keyWord);
           }
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }
    //---------------------------业务接口-借出明细表-----------------------end
}
